<cfscript>
	writeoutput("The big brown fox jump over the lazy dog.");
	public any function getFunctions(required string page,required string start, required string limit, required any sort, required any filter) 
	ExtDirect="true"
	{
		try
        {
        	
			where             = " (";
            tmpdatafield      = "";
            tmpfilteroperator = "0";
			
			try {
				filter = deserializejson(filter);	//Deserialize JSON string coz Router forgets to do the work on filter but not on sort
			for(a=1;a<=ArrayLen(filter);a++) {
				
            	try {
					filterdatafield = filter[a].field;
				} 
				catch(Any e)
                {
                  break;
                }

            	filterdatafield = filter[a].field;
				filterdatafield = replace(filterdatafield, "_", ".");
				filtervalue     = filter[a].value;
				filtertype      = filter[a].type;
				if( tmpdatafield == "" ) {
                	tmpdatafield = filterdatafield;	
                } else if( tmpdatafield != filterdatafield ) {
                	where = "#where# ) AND ( ";
                } else if( tmpdatafield == filterdatafield ) {
                	if( tmpfilteroperator == 0 ) {
                    	where = "#where# AND ";
                    } else {
                    	where = "#where# OR ";
                    }
				}
                
                if( ucase(filtertype) == "STRING" ) {
					where = "#where##filterdatafield#  LIKE '%#filtervalue#%'";
				} else if(  ucase(filtertype) == "NUMERIC" ) {
					filtercondition = filterdata.comparison;
					expression = "#Ucase(Trim(filtercondition))#";
               			if( expression  == "LT" ) {
						   	where = "#where##filterdatafield#  < #filtervalue#";
						} else if( expression == "GT" ) { 
							where = "#where##filterdatafield#  > #filtervalue#";
						} else if( expression == "EQ" ) {   	
							where = "#where##filterdatafield#  = #filtervalue#";
						}
				} else if(  ucase(filtertype) == "DATE" ) {
					filtercondition = filterdata.comparison;
					expression = "#Ucase(Trim(filtercondition))#";
					
						filtervalue = CreateODBCDateTime(filtervalue);
               			if( expression  == "LT") {
	               			where = "#where##filterdatafield#  < #filtervalue#";
						} else if( expression == "GT" ) {   
							where = "#where##filterdatafield#  > #filtervalue#";
						} else if( expression == "EQ" ) {   	
							where = "#where##filterdatafield#  = #filtervalue#";
						} else {
							where = "#where##filterdatafield#  = #filtervalue#";
					    }
				} else {
					//boolean
					 where = "#where##filterdatafield#  LIKE '%#filtervalue#%'";
				}
                tmpdatafield      = filterdatafield;
			}
		}
		catch(Any e)
		{
			//Do nothing here since filter is not a valid JSON string
		}
            
        where = "#where#)";
		where = Replace(where, "''", "'" , "all");
			
		if( trim(where) != "()" ) {
			WHERE =  "WHERE #PreserveSingleQuotes(where)#";
		} else {
			WHERE = "";
		}
		    
	  //Order By Arguments/Contents 
	  thecnt = 1;
	  for(b=1;b<=ArrayLen(sort);b++) {
	  	  ORDERBY = "#replace(sort[b].property, '_', '.')# #sort[b].direction#";
	  	  if( thecnt == ArrayLen(sort) ) {
		  } else {
	  	  	ORDERBY = ORDERBY & ',';
		  }
		  thecnt = thecnt + 1;
	  }
			
			
			
			processedData = ORMExecuteQuery("FROM EGLKSQLFUNCTIONS #WHERE# ORDER BY #ORDERBY#", false, {offset=#start#, maxResults=#limit#, timeout=60} );

			countAll = ORMExecuteQuery("SELECT SQLCODE FROM EGLKSQLFUNCTIONS #WHERE#" );
			
			rootstruct = StructNew();
			tmpresult = StructNew();
			resultArr = ArrayNew(1);
			
			for(i=1; i<=ArrayLen(processedData); i++) {
				tmpresult = StructNew();
				tmpresult['SQLCODE'] = processedData[i].getSQLCODE();
				tmpresult['FUNCTIONNAME'] = processedData[i].getFUNCTIONNAME();
				tmpresult['CATEGORY'] = processedData[i].getCATEGORY();
				tmpresult['SYNTAX'] = processedData[i].getSYNTAX();
				tmpresult['DEFINITION'] = processedData[i].getDEFINITION();
				tmpresult['DBMSNAME'] = processedData[i].getDBMSNAME(); 
				tmpresult['TOTALNOOFARGS'] = processedData[i].getTOTALNOOFARGS();
				tmpresult['REQUIREDNOOFARGS'] = processedData[i].getREQUIREDNOOFARGS();
				tmpresult['DEFAULTTYPE'] = processedData[i].getDEFAULTTYPE();
				tmpresult['TOTALNOOFARGS'] = processedData[i].getTOTALNOOFARGS();
				ArrayAppend(resultArr,tmpresult);
			}
			
			rootstuct['totalCount'] = ArrayLen(countAll);
			rootstuct['topics'] = resultArr; 
			return rootstuct;
    }
    catch(Any e)
    {
    	return e;
    }
  }

</cfscript>

<cfquery name="transparentquery" datasource="#session.global_dsn#" >
	SELECT *
	  FROM CMFPA
  ORDER BY FIRSTNAME
</cfquery>